﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace WSweb
{
    /// <summary>
    /// Summary description for mgHandler
    /// </summary>
    public class mgHandler : IHttpHandler
    {

        public void ProcessRequest (HttpContext context) 
        {
          SqlConnection c = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBwswebCS"].ConnectionString); 
          c.Open(); 
          string sql = "Select top 1 image,image_type from Vijest where image_id=@ImageId"; 
          SqlCommand comm = new SqlCommand(sql, c);
          comm.Parameters.AddWithValue("@ImageId", context.Request.QueryString["id"]);
          SqlDataReader dr = comm.ExecuteReader(); 
          dr.Read(); 
          context.Response.ContentType = dr["image_type"].ToString(); 
          context.Response.BinaryWrite((byte[])dr["image"]); 
          dr.Close();
          c.Close(); 
  
        }
        public bool IsReusable
        {
            get { return false; }
        }
    }
}